{include file='public:header-css'/}
<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        {include file='public:left-menu'/}
        <!--End 左侧导航-->
        <!--头部信息-->
        {include file='public:nav-header' title="商品管理" subTitle="商品列表"/}
        <!--End 头部信息-->

        <!--页面主要内容-->
        <main class="lyear-layout-content" id="app">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            {assign name="is_on_sale" value="$Request.param.is_on_sale|default=''" /}
                            <ul class="nav nav-tabs page-tabs">
                                <li {if $is_on_sale==''}class="active"{/if}><a href="{:url('Goods/goods_list',['is_on_sale'=>''])}">全部</a></li>
                                <li {if $is_on_sale=='-1'}class="active"{/if}><a href="{:url('Goods/goods_list',['is_on_sale'=>'-1'])}">待审核</a></li>
                                <li {if $is_on_sale=='-4'}class="active"{/if}><a href="{:url('Goods/goods_list',['is_on_sale'=>'-4'])}">下架</a></li>
                                <li {if $is_on_sale=='1'}class="active"{/if}><a href="{:url('Goods/goods_list',['is_on_sale'=>'1'])}">出售中</a></li>
                                <li {if $is_on_sale=='-3'}class="active"{/if}><a href="{:url('Goods/goods_list',['is_on_sale'=>'-3'])}">审核通过</a></li>
                                <li {if $is_on_sale=='-2'}class="active"{/if}><a href="{:url('Goods/goods_list',['is_on_sale'=>'-2'])}">审核失败</a></li>
                            </ul>
                            <div class="hint">
                                <div class="hint-info">
                                    <h5><i class="mdi mdi-help-circle-outline"></i>操作提示</h5>
                                    <p>平台所有商品列表</p>
                                    <p>推荐的商品才会在首页显示</p>
                                </div>
                            </div>
                            <div class="card-toolbar">
                                <div class="toolbar-btn-action">
                                    <a class="btn btn-label btn-theme" href="{:url('Goods/add_edit_goods')}"><label><i
                                            class="mdi mdi-plus-circle"></i></label> 添加商品</a>
                                    <a class="btn btn-label btn-danger" onclick="handel()"><label><i
                                            class="mdi mdi-delete"></i></label> 批量删除</a>
                                </div>
                                <div class="card-toolbar-center">
                                    <a href="" class="table-btn btn-dark"><i class="mdi mdi-replay"></i></a>
                                    <button class="table-btn btn-theme">共{$list->total()}条记录
                                        当前第{$list->currentPage()}页
                                    </button>
                                </div>
                                <form class="table-form" method="post" action="">
                                    <input type="hidden" name="is_on_sale" value="{$is_on_sale}">
                                    <div class="table-form-group">
                                        <input type="text" value="{$Request.param.keyword}" name="keyword"
                                               placeholder="查询名称或货号">
                                        <button class="btn btn-default" type="submit">搜索</button>
                                    </div>
                                </form>
                            </div>
                            <div class="card-body">
                                <table class="table table-bordered table-striped table-hover">
                                    <thead>
                                    <tr>
                                        <th>
                                            <label class="table-checkbox">
                                                <input type="checkbox" id="check-all"><span></span>
                                            </label>
                                        </th>
                                        <th style="width: 100px">操作</th>
                                        <th>ID</th>
                                        <th>商品名称</th>
                                        <th>货号</th>
                                        <th>所属商家</th>
                                        <th>市场价格</th>
                                        <th>商品价格</th>
                                        <th>成本价格</th>
                                        <th>运费价格</th>
                                        <th>商品库存</th>
                                        <th>商品主图</th>
                                        <th>上/下架</th>
                                        <th>是否推荐</th>
                                        <th>排序</th>
                                        <th>创建时间</th>
                                        <th>更新时间</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {if $list->isEmpty()}
                                    <tr>
                                        <td class="no-data" colspan="50">
                                            <i class="mdi mdi-alert-decagram"></i>没有符合条件的记录
                                        </td>
                                    </tr>
                                    {else/}
                                    {volist name="$list" id="vo"}
                                    <tr>
                                        <td>
                                            <label class="table-checkbox">
                                                <input type="checkbox" class="checkbox"
                                                       value="{$vo[$vo.pk]}"><span></span>
                                            </label>
                                        </td>
                                        <td><a class="table-btn btn-theme" href="{:url('Goods/add_edit_goods',['goods_id'=>$vo[$vo.pk]])}"><i class="mdi mdi-pencil"></i>编辑</a>
                                        </td>
                                        <td>{$vo[$vo.pk]}</td>
                                        <td>{$vo.goods_name}</td>
                                        <td>{$vo.goods_sn}</td>
                                        <td>{$vo.store.store_name}</td>
                                        <td>{$vo.market_price}</td>
                                        <td>{$vo.goods_price}</td>
                                        <td>{$vo.cost_price}</td>
                                        <td>{$vo.ship_price}</td>
                                        <td>{$vo.store_count}</td>
                                        <td class="img"><img title="点击图片看大图" data-toggle="tooltip" class="table-img" src="{$vo.goods_img}"></td>
                                        <td><span class="tag {if $vo.is_on_sale==1}label-success{else/}label-danger{/if}">{$vo.sale_text}</span>
                                        <td><span data-id="{$vo[$vo.pk]}" data-field="is_recommend"
                                                  class="open mdi {$vo.is_recommend==1 ? 'text-success mdi-checkbox-marked-circle-outline' : 'text-red mdi-close-circle-outline'}"> {$vo.recommend_text}</span>
                                        </td>
                                        <td><input data-id="{$vo[$vo.pk]}" type="text" class="table-input" value="{$vo.sort}"></td>
                                        <td>{$vo.add_time}</td>
                                        <td>{$vo.update_time}</td>
                                    </tr>
                                    {/volist}
                                    {/if}
                                    </tbody>
                                </table>
                                <div class="card-toolbar" style="padding: 0">
                                    <form class="table-form" method="post" action="">
                                        <div class="table-form-group">
                                            <div class="check-toolbar">
                                                <select name="check_state" class="input-group-select" v-model="is_on_sale">
                                                    <option value="-3">审核通过</option>
                                                    <option value="-2">审核失败</option>
                                                    <option value="-1">待审核</option>
                                                    <option value="0">下架</option>
                                                    <option value="1">上架</option>
                                                </select>
                                            </div>
                                            <button class="btn btn-default" type="button" @click="confirm">确定</button>
                                        </div>
                                    </form>
                                </div>
                                <!--分页-->
                                <div class="page">
                                    {$page|raw}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
        <!--End 页面主要内容-->
    </div>
</div>
<style>
    .check-toolbar .input-group-select:last-child{
        margin-right: -1px!important;
    }
</style>
<!--图片预览插件-->
<script type="text/javascript">
    var _this;
    var app = new Vue({
        el: '#app',
        data: {
            check_state:0,
            is_on_sale:-3,
        },
        created() {
            _this=this
        },
        methods: {
            confirm(){
                var checkbox = $('.checkbox:checked');
                if (checkbox.length == 0) {
                    showErrorMsg("请选择数据");
                    return
                }
                var ids = [];
                $.each(checkbox, function (index, item) {
                    ids.push(item.value)
                });
                var url = "{:url('Goods/check_goods')}";
                var data = {'ids': ids, 'is_on_sale': _this.is_on_sale};
                public_ajax(url, data, function (res) {
                    if (res.code==1){
                        showSuccessMsg(res.msg,function () {
                            location.reload()
                        })
                    }else {
                        showErrorMsg(res.msg);
                    }
                })
            }
        },
        mounted(){

        }
    });
    $(function () {
        layer.photos({
            photos: '.img'
            ,anim: 5
        });
        $('.open').on('click', function () {
            if ($(this).hasClass('text-success')) {
                var is_on_sale = 0;
                var add = 'text-red mdi-close-circle-outline';
                var remove = 'text-success mdi-checkbox-marked-circle-outline';
                var text = ' 否';
            } else {
                var is_on_sale = 1;
                var add = 'text-success mdi-checkbox-marked-circle-outline';
                var remove = 'text-red mdi-close-circle-outline';
                var text = ' 是';
            }
            var id = $(this).attr('data-id');
            var field = $(this).attr('data-field');
            var obj = $(this);
            changeTableVal('goods', field, id, is_on_sale, function (res) {
                if (res.code == 1) {
                    obj.removeClass(remove).addClass(add).text(text);
                }
            });
        });
        $('.table-input').on('blur',function () {
            var id=$(this).attr('data-id');
            var val=$(this).val();
            if (val==''){
                showErrorMsg("请输入排序");
                return;
            }
            changeTableVal('goods', 'sort', id, val, function (res) {
            });
        });
    });
    function handel() {
        var checkbox = $('.checkbox:checked');
        if (checkbox.length == 0) {
            showErrorMsg("请选择数据");
            return
        }
        var ids = [];
        $.each(checkbox, function (index, item) {
            ids.push(item.value)
        });
        var text = "确认操作?";
        showConfirm(text, function () {
            var url = "{:url('Goods/delGoods')}";
            var data = {'ids': ids};
            public_ajax(url, data, function (res) {
                if (res.code==1){
                    showSuccessMsg(res.msg,function () {
                        location.reload()
                    })
                }else {
                    showErrorMsg(res.msg);
                }
            })
        })
    }
</script>
</body>
</html>
